package com.jlcindia.action.classes;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jlc.connPage.JDBCUtil;

public class ForgetPassowrdAction {

	public ForgetPassowrdAction() {
		System.out.println("ForgetPassowrdAction() Cons Invoked, means object is created");
	}

	Connection con=null;
	PreparedStatement ps=null;
	ResultSet rs=null;
	
	public String forgetPasswordUser(HttpServletRequest request,
			HttpServletResponse response) {
		System.out.println("~~~~~~forgetPasswordUser() method invoked~~~~~");
		String email = request.getParameter("email");
		String page = "forgetpwd.jsp";

		try {
			con=JDBCUtil.getMysqlConnection();
			ps=con.prepareStatement("select password from userInfo where email=?");
			ps.setString(1, email);
			rs=ps.executeQuery();
			if(rs.next()){
				String pass=rs.getString("password");
				System.out.println(pass);
				page = "forgetpwd.jsp";
				request.setAttribute("SUCCESS", "Your Password sent on your mail successfully");
			}else{
				page = "forgetpwd.jsp";
				request.setAttribute("ERROR", "Sorry! Wrong Email ID, Tray again");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return page;

	}

}
